package com.zfzs.post.service.impl;

import com.zfzs.post.exception.BadRequestException;
import com.zfzs.post.modules.agent.service.dto.AgentDTO;
import com.zfzs.post.modules.lesson.domain.Lesson;
import com.zfzs.post.modules.lesson.service.LessonService;
import com.zfzs.post.service.JwtUserDetailsService;
import com.zfzs.post.service.LessonApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wq
 * @date 2019/12/4 14:45
 * @description
 */
@Service
public class LessonApiServiceImpl implements LessonApiService {

    @Autowired
    private LessonService lessonService;

    @Autowired
    private JwtUserDetailsService jwtUserDetailsService;

    @Override
    public Map<String, Object> getLessonInfo() {
        AgentDTO agentInfo = JwtUserDetailsService.getAgentInfo();
        Lesson lesson=new Lesson();
        lesson.setChannelId(agentInfo.getChannelId());
        lesson.setIsDel(0);
        lesson.setType(1);

        Lesson one = lessonService.findOne(lesson);

        lesson.setType(2);
        List<Lesson> list = lessonService.findList(lesson);


        Map<String,Object> result=new HashMap<>(2);

        result.put("headImg",one!=null?one:new Lesson());
        result.put("list",list);
        return result;
    }

    @Override
    public Lesson getLessonById(Integer lessonId) {
        if(lessonId==null || lessonId==0){
            throw new BadRequestException("无效的id");
        }
        return lessonService.findById(lessonId);
    }
}
